package com.xinfang.superminer.view.pop;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.xinfang.superminer.R;
import com.xinfang.superminer.activity.peth.AddPethActivity;
import com.xinfang.superminer.activity.peth.AddPoolActivity;
import com.xinfang.superminer.activity.peth.CurrencyInformationActivity;


/**
 * 添加钱包或矿池的pop
 * Created by th1 on 2016/11/4.
 */
public class AddPethAndPoolPopupWindow extends PopupWindow implements View.OnClickListener {

    private View view;
    private Activity context;

    //添加矿池
    private LinearLayout ll_addpool;

    //t添加钱包
    private LinearLayout ll_addpeth;


    private int id;
    private String name;//币种名称

    public AddPethAndPoolPopupWindow(Activity context, String name,int id) {
        super(context);
        this.context = context;
        this.id=id;
        this.name=name;
        view = LayoutInflater.from(context).inflate(R.layout.pop_add_peth_pool, null);
        initPop();
        initView();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        ll_addpool = (LinearLayout) view.findViewById(R.id.ll_addpool);
        ll_addpool.setOnClickListener(this);
        ll_addpeth = (LinearLayout) view.findViewById(R.id.ll_addpeth);
        ll_addpeth.setOnClickListener(this);
    }

    /**
     * 样式
     */
    private void initPop() {
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);


        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

        this.setContentView(view);

//        setAnimationStyle(R.style.mypopwindow_anim_style);
        ColorDrawable dw = new ColorDrawable(Color.parseColor("#00000000"));
        //设置SelectPicPopupWindow弹出窗体的背景
        setBackgroundDrawable(dw);

        backgroundAlpha(1.0f);
        setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                backgroundAlpha(1f);
            }
        });
        //获取popwindow焦点
        setFocusable(true);
        //设置popwindow如果点击外面区域，便关闭。
        setOutsideTouchable(true);
    }

    public void backgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = context.getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0
        context.getWindow().setAttributes(lp);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_addpool:
                //添加矿池
                Intent intent = new Intent(context, AddPoolActivity.class);
                intent.putExtra("id",id);
                intent.putExtra("name",name);
                context.startActivityForResult(intent, CurrencyInformationActivity.PETHREQUSETCODE);
                dismiss();
                break;
            case R.id.ll_addpeth:
                //添加钱包
                Intent intent1 = new Intent(context, AddPethActivity.class);
                intent1.putExtra("id",id);
                intent1.putExtra("name",name);
                context.startActivityForResult(intent1, CurrencyInformationActivity.PETHREQUSETCODE);
                dismiss();
                break;
        }
    }


}
